import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'

const instance = axios.create({
  baseURL:'http://localhost:3000/'
})
Vue.prototype.$axios = instance;

instance.interceptors.request.use(
  (config) => {
      // 在发送请求之前做些什么
      // config.headers['Authorization'] = ''
      return config;
  }, 
  (error) => {
      // 对请求错误做些什么
      return Promise.reject(error);
  }
);

// 添加响应拦截器
instance.interceptors.response.use(
  (response) => {
    // console.log(response);
      if(response.status===500){
          console.log('请求失败')
      }
      return response.data;
  }, 
  (error) => {
      if(error.response.status==404){
          console.log(error.response)
      }
      return Promise.reject(error);
  }
);

Vue.config.productionTip = false
Vue.use(ElementUI);

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
